﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using Job.Web.Framework;
using Job.Logic.BaseContent;
using Job.Entity;
using Job.Logic.Common;

namespace Job.Web.userControls.Hunter
{
    public partial class HunterJobItem : BaseCtrl
    {
        string jobNo = myR["jobno"].StringValue;

        protected void Page_Load(object sender, EventArgs e)
        {
            if (this.IsPostBack) return;

            MySession session = new MySession();

            btnAddFavorites.Visible = (session.GetPersonalFromSession() != null);
            btnSendResumt.Visible = (session.GetPersonalFromSession() != null);
            userTr.Visible = (session.GetPersonalFromSession() == null);

            HunterJobLogic logic = new HunterJobLogic();
            JobHunter job = logic.GetDetail(jobNo);
            if (null == job)
            {
                Response.Write("<script>");
                Response.Write("  alert('查询的职位已不存在！');");
                Response.Write("  history.back();");
                Response.Write("</script>");
                Response.Flush();
                return;
            }

            this.lbJobNo.Text = job.JobNo;
            this.lbJobName.Text = job.Name;
            this.lbIndustry.Text = MemoryDictionary.GetFullIndustryName(job.Industry);
            this.lbSalary.Text = MemoryDictionary.GetCommonDictName(job.Salary);
            //this.lbAddress.Text = job.OfficeAddress;
            this.lbAddress.Text = MemoryDictionary.GetFullAddrName(job.OfficeAddress);
            this.lbResponsibility.Text = Functions.HtmlEncode(job.Responsibility);
            this.lbRequired.Text = Functions.HtmlEncode(job.Grade);
            this.lbLinkman.Text = job.ContactName;
            this.lbLinkPhone.Text = job.ContactTel;
            this.lbLinkMail.Text = job.Email;
            this.lbLastModify.Text = job.CreateDate.Value.ToString("yyyy-MM-dd");

            BindClickEvent();

        }
        
        private void BindClickEvent()
        {
            string url = WebCommon.GetApplicationPath(Request)
                + "Person/AddFavorites.aspx?job=" + jobNo;
            string features = "height=250, width=320, toolbar=no,menubar=no, scrollbars=no,"
                + "resizable=no,location=no, status=no";
            string js1 = "window.open('" + url + "','Favorite','" + features + "');";
            this.btnAddFavorites.Attributes.Add("onclick",js1);

            url = WebCommon.GetApplicationPath(Request)
                + "Person/SendResume.aspx?job=" + jobNo;
            features = "height=250, width=620, toolbar=no,menubar=no, scrollbars=no,"
                            + "resizable=no,location=no, status=no";
            string js2 = "window.open('" + url + "','Favorite','" + features + "');";
            this.btnSendResumt.Attributes.Add("onclick", js2);
        }

        protected void btSearch_Click(object sender, ImageClickEventArgs e)
        {
            String searchKey = tbSearchKey.Text.Trim();
            String url = WebCommon.GetApplicationPath(Request)
                                + "Item.aspx?categoryid=" + ((int)Constants.CategoryType.Hunter).ToString()
                                + "&subjectid=" + ((int)Constants.SubjectType.HunterPositionList).ToString()
                                + "&key=" + searchKey;
            Response.Redirect(url);
        }
    }
}